<?php
/**
 * Created by PhpStorm.
 * User: renyi
 * Date: 2017/10/15
 * Time: 下午13:34
 */

namespace App\Misc;


use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class DBToolkit
{
    public static function enable()
    {
        DB::connection()->enableQueryLog();
    }

    public static function disable()
    {
        DB::connection()->disableQueryLog();
    }

    public static function get()
    {
        return DB::connection()->getQueryLog();
    }

    public static function log($mark = "")
    {
        $sql = self::get();

        if (is_array($sql))
        {
            Log::info("Log SQL mark[$mark] = ", $sql);
        }
        else
        {
            Log::info("Log SQL mark[$mark] = $sql");
        }
    }

    public static function show()
    {
        dg("sql = " . DB::connection()->getQueryLog());
    }
}